<?php
/**
 * Created by PhpStorm.
 * User: zhan
 * Date: 2019/1/4  10:48
 */
namespace app\driver\logic;
use app\driver\BaseModel;
use think\Cache;
use think\Db;
class System extends  BaseModel
{

    //检测参数是否已传
    protected $ParameterDetection = [

    ];


    /**
     *绑定银行卡
     */
    public function editbankcard()
    {
        (new \app\api\validate\System())->bindcard();
        $is_edit = isset($this->requestData['is_edit']) ? $this->requestData['is_edit'] : '0';

        $db_bankcard = db("driver_bankcard");
        $code = trim($this->requestData['code']);
        if (base64_encode($code) != Cache::get($this->requestData['mobile'])) {
            return array('message' => '验证码错误');
        }
        $data = [
            'name' => $this->requestData['name'],
            'card_num' => $this->requestData['card_num'],
            'bank' => $this->requestData['bank'],
            'mobile' => $this->requestData['mobile'],
            "driver_id" => $this->user['id'],
        ];
        $card = $db_bankcard->where(['driver_id' => $this->user['id']])->find();

        if ($is_edit != '1') {
            if ($card) return array("message" => '无需重复绑定');
            $res = $db_bankcard->insert($data);
        } else {
            $res = $db_bankcard->where(['driver_id' => $this->user['id']])->update($data);
        }

        if (!$res) return array("message" => '绑定失败');
    }

    /**
     * 银行卡详情
     */
    public function bankcardInfo()
    {
        $db_bankcard = db("driver_bankcard");
        $card=$db_bankcard->where("driver_id=". $this->user['id'])->find();
        if(!$card) return array("message"=>'还没绑定银行卡');
        return $card;
    }
    /**
     * 解绑银行卡
     */
    public function delbankcard()
    {
        $db_bankcard = db("driver_bankcard");
        $res=$db_bankcard->where("driver_id=".$this->user['id'])->delete();
        if(!$res) return array("message"=>'解绑失败');
    }


}